package servlet.User;

import Model.User;
import appexception.AppException;
import service.BaseService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @program: wsn_blog
 * @description
 * @author:王松年
 * @creat: 2021-07-12 15:52:35
 **/

@WebServlet("/logout")
public class UserLogoutServlet extends BaseService {
    @Override
    protected void query(HttpServletRequest req, HttpServletResponse resp) throws SQLException, IOException {
        HttpSession session = req.getSession(false);
        if (session == null) {
            throw new AppException("LOGOUT001", "未登录");
        }
        User user = (User) session.getAttribute("user");
        if (user == null) {
            throw new AppException("LOGOUT002", "未登录");
        }
        //已登录：从session中删除user
        session.removeAttribute("user");
    }
}